#include <bits/stdc++.h>
#define PII pair<int, int>
#define db long double
#define ull unsigned long lon   g
#define uint unsigned int
#define mp make_pair
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define sec second
#define fi frist
using namespace std;

bool S;
const string Fn = "color";
const int MOD = 998244353, N = 200050;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int T = 1, n, m, a[N];

inline void read(int &x) {
    int f = 1; x = 0;
    char c = getchar();
    if (c == '-') f = -1;
    while (c > '9' || c < '0') {
        c = getchar();
        if (c == '-') f = -1;
    }
    while (c <= '9' && c >= '0') 
        x = x * 10 + (c - '0'), c = getchar();
    x *= f;
    return;
}
int solve(int x) {
    int sum = 0, pre1 = -1, pre2 = -1;
    for (int i = 1; i <= n; i++) {
        if (1 & (x >> (i - 1))){
            if (pre1 == a[i]) sum += a[i];
            pre1 = a[i];
        }
        else {
            if (pre2 == a[i]) sum += a[i];
            pre2 = a[i];
        }
    }
    return sum;
}
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> T;
    while (T--) {
        cin >> n; int ans = 0;;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        for (int i = 0; i < (1 << n); i++) {
            ans = max(ans, solve(i));
        }
        cout << ans << endl;
    }
    return 0;
}
/*
g++ color.cpp -o color -O2
3
3
1 2 1
4
1 2 3 4
8
3 5 2 5 1 2 1 4
*/